<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//Dtd bgcolor="ffffff" HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd bgcolor="ffffff"">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<% String cpath = request.getContextPath(); %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>쿠폰리스트(관리자)</title>
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>

<script type="text/javascript">
function del(coupon_num){
	
	if(confirm("삭제하시겠습니까?")){
		$.ajax({
		  url:'<%=cpath %>/coupon/delete',
		  dataType:'html',
		  type:'get',
		  data: {coupon_num:coupon_num},
		  success: function(data) {
		  	alert("삭제되었습니다.");
		   	history.go(0);  /* 페이지 새로고침 */
		  },
		  error:function(){
		  	alert("삭제실패!!");
		  }
		}); 
	}
	<%--if(confirm("삭제하시겠습니까?"))
	 location.href="<%=cpath %>/coupon/delete?coupon_num="+coupon_num; --%>
}
</script>

<link href="<%=cpath%>/resources/css/coupon_css.css" rel="stylesheet" type="text/css">
</head>
<body>

<p>쿠폰개수:${listDTO.listcount }</p>

<table width="1300" height="265" align="center" border="0" cellspacing="1" bgcolor="#FFC0CB">
  <tr>
   <td height="62" colspan="11" bgcolor="ffffff">
  	<span class="style5">쿠폰리스트</span>   </td>
  </tr>

  <tr>
   	<td width="100" height="33" bgcolor="ffffff">쿠폰번호</td>
    <td width="100" bgcolor="ffffff">쿠폰명</td>
    <td width="200" bgcolor="ffffff">유의사항</td>
    <td width="100" bgcolor="ffffff">시작일</td>
    <td width="100" bgcolor="ffffff">종료일</td>
    <td width="200" bgcolor="ffffff">상세</td>
    <td width="60" bgcolor="ffffff">할인율</td>
    <td width="80" bgcolor="ffffff">조회수</td>
    <td width="80" bgcolor="ffffff">이미지</td>
    <td width="100" bgcolor="ffffff">등록일</td>
    <td width="80" bgcolor="ffffff">관리</td>
  </tr>
     <!-- 등록된 상품 없음 -->
  <c:if test="${listDTO.listcount == 0}">
    <tr>
      <td height="25" colspan="11" bgcolor="ffffff">등록된 상품이 없습니다.</td>
    </tr>
  </c:if>
  <!-- 등록상품 있을경우 -->
  <c:if test="${listDTO.listcount != 0}">
    <c:forEach items="${listDTO.list }" var="list">
      <tr> 
      <%-- onMouseOver="this.style.color='pink'" onMouseOut="this.style.color='black'" 
      onClick="location.href='<%=cpath %>/coupon/detail?coupon_num=${list.coupon_num}'"  --%>
 
        <td bgcolor="#ffffff">${list.coupon_num }</td>
        <td bgcolor="#ffffff">${list.coupon_name }</td>
        <td bgcolor="#ffffff">${list.coupon_notice}</td>
        <td bgcolor="#ffffff">${list.coupon_startdate }</td>
        <td bgcolor="#ffffff">${list.coupon_enddate }</td>
        <td bgcolor="#ffffff">${list.coupon_details }</td>
        <td bgcolor="#ffffff">${list.coupon_discount }</td>
        <td bgcolor="#ffffff">${list.coupon_readcnt  }</td>
        <td bgcolor="#ffffff"><img src="/food/resources/coupon/${list.coupon_image}" width="100" height="100" border="0"></td>
        <td bgcolor="#ffffff">${list.coupon_indate }</td>
        
        <td bgcolor="#ffffff">
        	<input type="button" value="수정" onClick="location.href='<%=cpath %>/coupon/updatePage?coupon_num=${list.coupon_num}&curPage=${listDTO.curPage} '" />
          <input type="button" value="삭제" onClick="javascript:del(${list.coupon_num })">  
          <!-- 리스트에서 삭제시 삭제완료후 새로고침됨 -->
          <input type="button" value="상세보기" onClick="location.href='<%=cpath %>/coupon/detail?coupon_num=${list.coupon_num}&curPage=${listDTO.curPage}'" >
          
        </td>
      
      </tr>
    </c:forEach>
  </c:if>
  <tr>
  <td colspan="11" bgcolor="#ffffff">
  <!--페이징처리 -->
  
  <!-- 이전 링크[이전] -->

	<c:if test="${listDTO.prevPage > 0}">
	<a href="<%=cpath%>/coupon/list?curPage=${listDTO.prevPage }">[이전]</a>
	</c:if>
	
	
	<!-- 페이지 -->
	<!-- 조건절(현재페이지에서는 링크 없고, 다른페이지만 링크보이게) -->
	<c:forEach var="cnt" begin="${listDTO.firstPage }" end="${listDTO.lastPage }" step="1">
		<c:choose>
			<c:when test="${cnt == listDTO.curPage }">
				[${cnt }]
			</c:when>
			<c:otherwise>
				<a href="<%=cpath%>/coupon/list?curPage=${cnt }">[${cnt }]</a>
			</c:otherwise>
		</c:choose>
	</c:forEach>
	<!-- 다음 링크[다음] -->
	<c:if test="${listDTO.nextPage >0 }">
	<a href="<%=cpath%>/coupon/list?curPage=${listDTO.nextPage }">[다음]</a>
	</c:if>  </td>
  </tr>
 
</table>

<br>
<input type="button" value="쿠폰등록" onClick="location.href='<%=cpath%>/coupon/insert'">
<p>&nbsp;</p>
</body>
</html>